<template>
  <!-- 评标结果 -->
  <j-modal
    :title="title"
    :width="1200"
    :visible="visible"
    :maskClosable="false"
    switchFullscreen
    :fullscreen="true"
    @ok="handleOk"
    :okButtonProps="{ class: { 'jee-hidden': disableSubmit } }"
    @cancel="handleCancel"
  >
    <template slot="footer">
      <a-button @click="handleCancel">关闭</a-button>
    </template>
    <a-row type="flex" :span="4">
      <a-col flex="150px">
        <a-card>
          <!-- {{expertList}} -->
          <a-tree :tree-data="treeData" show-icon default-expand-all :default-selected-keys="['0']" @select="onSelect">
            <template slot="custom" slot-scope="{ selected }">
              <a-icon :type="selected ? 'frown' : 'frown-o'" />
            </template>
          </a-tree>
        </a-card>
      </a-col>
      <a-col flex="auto" :span="18">
        <FhxTenderDetail
          v-show="selectedKey.indexOf('fhx_') !== -1"
          ref="fhxDetailRef"
          :bidSectionId="sectionId"
          :businessId="selectBusinessId"
        />
        <FhxSum
          v-show="selectedKey.indexOf('fhxhz_') !== -1"
          ref="fhxSumRef"
          :bidSectionId="sectionId"
          :businessId="selectBusinessId"
        />
        <ExpertList  v-show="selectedKey == 0" :bidSectionId="sectionId" />
        <ExpertRecommendRecordList  v-show="selectedKey == 0" :bidSectionId="sectionId" />

        <PfExpertTenderDetail v-show="selectedKey.indexOf('pfbz_') !== -1"
                        ref="pfbzDetailRef"
                        :bidSectionId="sectionId"
                        :businessId="selectBusinessId"/>
        <PfhzTenderDetail v-show="selectedKey.indexOf('pfbzhz_') !== -1"
                              ref="pfhzDetailRef"
                              :bidSectionId="sectionId"
                              :businessId="selectBusinessId"/>
      </a-col>
    </a-row>
  </j-modal>
</template>
<script>
import { getAction, postAction } from '@api/manage'
import FhxTenderDetail from '@views/exPingbiao/result/FhxTenderDetail'
import FhxSum from '@views/exPingbiao/result/FhxSum'
import ExpertList from '@views/exPingbiao/result/ExpertList'
import ExpertRecommendRecordList from '@views/exPingbiao/result/ExpertRecommendRecordList'
import PfExpertTenderDetail from '@views/exPingbiao/result/PfExpertTenderDetail.vue'
import PfhzTenderDetail from '@views/exPingbiao/result/PfhzTenderDetail.vue'

const treeData = [
  {
    title: 'parent 1',
    key: '0-0',
    children: [
      { title: 'leaf', key: '0-0-0' },
      { title: 'leaf', key: '0-0-1' },
    ],
  },
]

export default {
  components: { ExpertList, FhxTenderDetail, FhxSum ,PfExpertTenderDetail,PfhzTenderDetail,ExpertRecommendRecordList},
  props: {},
  data() {
    return {
      treeData,
      title: '',
      width: 800,
      visible: false,
      disableSubmit: false,
      openKeys: [],
      projectId: null,
      selectedKeys: '',
      activityList: [],
      projectDetail: {},
      sectionInfo: {},
      sectionId: '',
      loading: false,
      url: {
        // 根据项目ID以及标段ID查询详情
        queryByProjectIdAndSectionId:
          '/ExZbwjBidEvaluationConfig/exZbwjBidEvaluationConfig/queryByProjectIdAndSectionId',
        queryExpertList: '/exPingbiao/exPingbiaoExpert/expertList',
      },
      currentItem: {
        index: 0,
      },
      // 审查项列表
      reviewItemList: [],
      columns: [
        {
          title: '审查项',
          align: 'center',
          dataIndex: 'reviewItem',
        },
        {
          title: '审查标准',
          align: 'center',
          dataIndex: 'reviewStandard',
        },
        {
          title: '审查结果',
          align: 'center',
          dataIndex: 'action',
          scopedSlots: { customRender: 'action' },
        },
      ],
      tenderSelectedRowKeys: [],
      tenderListData: [],
      rejectTenderList: [],
      selectTenderId: '', //选中的投标人
      selectTenderName: '',
      groupFlag: false,
      completeFlag: false,
      lastFlag: false,
      activeKey: '1',
      sectionDetail: {
        currentItemIndex: 0,
      },
      expertList: [],
      selectBusinessId: '', //选中的业务id
      selectedKey: '', //
    }
  },
  computed:{
  },
  watch: {},
  mounted() {},
  methods: {
    onSelect(selectedKeys, info) {
      var that = this
      var key = selectedKeys[0]
      if(!key){
        return;
      }
      this.selectedKey = key
      if (key.indexOf('fhx_') !== -1) {
        //符合性
        this.selectBusinessId = key.replace('fhx_', '')
        that.$refs.fhxDetailRef.loadData(this.selectBusinessId, this.expertList)
      } else if (key.indexOf('fhxhz_') !== -1) {
        //符合性汇总
        this.selectBusinessId = key.replace('fhxhz_', '')
        that.$refs.fhxSumRef.loadData(this.selectBusinessId)
      } else if (key.indexOf('pfbz_') !== -1) {
        //评分标准
        this.selectBusinessId = key.replace('pfbz_', '')
        that.$refs.pfbzDetailRef.loadData(this.selectBusinessId, this.expertList)
      } else if (key.indexOf('pfbzhz_') !== -1) {
        //评分标准汇总
        this.selectBusinessId = key.replace('pfbzhz_', '')
        that.$refs.pfhzDetailRef.loadData(this.selectBusinessId)
      }
    },
    onCheck(checkedKeys, info) {
      console.log('onCheck', checkedKeys, info)
    },
    loadItem() {
      var that = this
      let params = {
        sectionId: this.sectionId,
      }
      this.treeData = [
        {
          title: '组长产生情况',
          key: '0',
        },
      ]
      getAction(this.url.queryByProjectIdAndSectionId, params)
        .then((res) => {
          if (res.success) {
            this.sectionDetail = res.result
            this.activityList = res.result.itemList
            for (let index = 0; index < this.activityList.length; index++) {
              const element = this.activityList[index]

              // that.expertList.forEach((row) => {
              //   childrenList.push({ title: row.name, key: 'zj_' + row.expertId })
              // })
              var businessType = element.type == 1 ? 'pfbz' : 'fhx'
              var childrenList = [{ title: '汇总表', key: businessType + 'hz_' + element.businessId }]
              this.treeData.push({
                title: element.businessName,
                key: businessType + '_' + element.businessId,
                children: childrenList,
              })
            }
          }
        })
        .finally(() => {})
    },

    // 专家列表
    queryExpertList(callback) {
      getAction(this.url.queryExpertList, { sectionId: this.sectionId })
        .then((res) => {
          if (res.success) {
            console.log(res.result)
            this.expertList = res.result
            setTimeout(() => {
              if(callback){
                callback()
              }
            }, 300)
          }
        })
        .finally(() => {})
    },
    show(record) {
      this.sectionInfo = Object.assign({}, record)
      this.visible = true
      this.sectionId = record.id
      this.queryExpertList(this.loadItem()) //专家列表
    },
    handleOk() {
      this.$refs.realForm.handleOk()
    },
    submitCallback() {
      this.$emit('ok')
      this.visible = false
    },
    handleCancel() {
      this.close()
    },
    close() {
      this.visible = false
    },
  },
}
</script>

<style scoped>
.item-container {
  .item {
    height: 40px;
    line-height: 40px;
    cursor: pointer;
    text-align: center;
    font-size: 16px;
  }
}

.selected {
  color: #1890ff;
}
</style>
